package com.lzh.fastjson.deserializer;

import com.alibaba.fastjson.parser.DefaultJSONParser;
import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;

import java.lang.reflect.Type;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

/**
 * @author zhehen.lu
 * @date 2025/8/10 14:40
 */
public class FastjsonLocalTimeDeserializer implements ObjectDeserializer {
    public FastjsonLocalTimeDeserializer() {
    }

    @Override
    public LocalTime deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
        String stringVal = parser.getLexer().stringVal();
        return stringVal == null ? null : LocalTime.parse(stringVal, DateTimeFormatter.ofPattern("HH:mm:ss"));
    }

    @Override
    public int getFastMatchToken() {
        return 0;
    }
}
